<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增销售出库')" />
    <th:block th:include="include :: datetimepicker-css" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 select-table table-striped">
            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-label">
                    <div id="id2toggle" class="fa fa-toggle-off text-info fa-3x" onclick="inStart()">
                        <i class="fa" style="font-size: 45%;vertical-align:45%;">扫码枪录入</i>
                        <textarea id="msg2saoma" oninput="check2input4piliang()" style="height: 0;width: 0;border: 0;padding: unset"></textarea>
                    </div>
                </a>
            </div>
            <div class="col-sm-6" style="display: flex;">
                <div class="col-sm-6" style="padding-top: 20px" th:with="type=${session.xiaoshouchuku2saoma}">
                    <div hidden id="id2saoma" th:value="${type.getId()}"></div>
                    <div th:unless="${type.getMen1Shuliang() eq '' || type.getMen1Shuliang() eq null}">
                        <div style="margin-top: 20px" th:text="'配套类型：'+${type.getPeitao1()}"></div>
                        <div style="margin-top: 20px" th:text="'门扇名称：'+${type.getGoodNameMen1()}"></div>
                        <div style="margin-top: 20px" th:text="'门扇规格：'+${type.getMen1shanKuan()+'*'+type.getMen1shanGao()+'&nbsp;&nbsp;&nbsp;&nbsp;'+type.getKaiXiang1()}"></div>
                        <div style="margin-top: 20px" th:text="'门扇数量：'+${type.getMen1Shuliang()}"></div>
                    </div>
                    <div th:unless="${type.getMen2Shuliang() eq ''|| type.getMen2Shuliang() eq null}">
                        <div style="margin-top: 20px" th:text="'右扇名称：'+${type.getGoodNameMen2()}"></div>
                        <div style="margin-top: 20px" th:text="'右扇规格：'+${type.getMen2shanKuan()+'*'+type.getMen2shanGao()+'&nbsp;&nbsp;&nbsp;&nbsp;'+type.getKaiXiang2()}"></div>
                        <div style="margin-top: 20px" th:text="'右扇数量：'+${type.getMen2Shuliang()}"></div>
                    </div>
                    <div th:unless="${type.getKuangShuliang() eq '' || type.getKuangShuliang() eq null}">
                        <div style="margin-top: 20px" th:text="'门框名称：'+${type.getGoodNameKuang()}"></div>
                        <div style="margin-top: 20px" th:text="'门框规格：'+${type.getKuangKuan()+'*'+type.getKuangGao()+'&nbsp;&nbsp;&nbsp;&nbsp;'+type.getKaiXiang3()}"></div>
                        <div style="margin-top: 20px" th:text="'门框数量：'+${type.getMen2Shuliang()}"></div>
                    </div>
                    <div th:unless="${type.getShuliang3() eq '' || type.getShuliang3() eq null}">
                        <div style="margin-top: 20px" th:text="'防火锁数量：'+${type.getShuliang1()}"></div>
                        <div style="margin-top: 20px" th:text="'闭门器数量：'+${type.getShuliang2()}"></div>
                        <div style="margin-top: 20px" th:text="'拉爆盖数量：'+${type.getShuliang3()}"></div>
                    </div>
<!--                    <div th:text="${type}"></div>-->
                </div>
                <div class="col-sm-6">
                    <div style="font-size: medium">已扫码物品</div>
                        <div style="margin-top: 20px"
                             th:unless="${session.xiaoshouchuku2saoma.getMen1Shuliang() eq '' || session.xiaoshouchuku2saoma.getMen1Shuliang() eq null}">
                            <div style="margin-top: 20px" th:text="'配套类型：'+${session.xiaoshouchuku2saoma.getPeitao1()}"></div>
                            <div style="margin-top: 20px" th:text="'门扇名称：'+${session.xiaoshouchuku2saoma.getGoodNameMen1()}"></div>
                            <div style="margin-top: 20px" th:text="'门扇规格：'+${session.xiaoshouchuku2saoma.getMen1shanKuan()+'*'+session.xiaoshouchuku2saoma.getMen1shanGao()+'&nbsp;&nbsp;&nbsp;&nbsp;'+session.xiaoshouchuku2saoma.getKaiXiang1()}"></div>
                            <div style="margin-top: 20px"
                                 th:text="'门扇数量：'+${@xiaoshouChukuServiceImpl.selectTodo(session.xiaoshouchuku2saoma.getGoodNameMen1(),
                                 session.xiaoshouchuku2saoma.getChukuDanhao(),session.xiaoshouchuku2saoma.getFahuoDanhao())}"></div>
                        </div>
                        <div style="margin-top: 20px"
                             th:unless="${session.xiaoshouchuku2saoma.getMen2Shuliang() eq ''|| session.xiaoshouchuku2saoma.getMen2Shuliang() eq null}">
                            <div style="margin-top: 20px" th:text="'右扇名称：'+${session.xiaoshouchuku2saoma.getGoodNameMen2()}"></div>
                            <div style="margin-top: 20px" th:text="'右扇规格：'+${session.xiaoshouchuku2saoma.getMen2shanKuan()+'*'+session.xiaoshouchuku2saoma.getMen2shanGao()+'&nbsp;&nbsp;&nbsp;&nbsp;'+session.xiaoshouchuku2saoma.getKaiXiang2()}"></div>
                            <div style="margin-top: 20px"
                                 th:text="'右扇数量：'+${@xiaoshouChukuServiceImpl.selectTodo(session.xiaoshouchuku2saoma.getGoodNameMen2(),
                                 session.xiaoshouchuku2saoma.getChukuDanhao(),session.xiaoshouchuku2saoma.getFahuoDanhao())}"></div>
                        </div>
                        <div style="margin-top: 20px"
                             th:unless="${session.xiaoshouchuku2saoma.getKuangShuliang() eq '' || session.xiaoshouchuku2saoma.getKuangShuliang() eq null}">
                            <div style="margin-top: 20px" th:text="'门框名称：'+${session.xiaoshouchuku2saoma.getGoodNameKuang()}"></div>
                            <div style="margin-top: 20px" th:text="'门框规格：'+${session.xiaoshouchuku2saoma.getKuangKuan()+'*'+session.xiaoshouchuku2saoma.getKuangGao()+'&nbsp;&nbsp;&nbsp;&nbsp;'+session.xiaoshouchuku2saoma.getKaiXiang3()}"></div>
                            <div style="margin-top: 20px"
                                 th:text="'门框数量：'+${@xiaoshouChukuServiceImpl.selectTodo(session.xiaoshouchuku2saoma.getGoodNameKuang(),
                                 session.xiaoshouchuku2saoma.getChukuDanhao(),session.xiaoshouchuku2saoma.getFahuoDanhao())}"></div>
                        </div>
                        <div style="margin-top: 20px"
                             th:unless="${session.xiaoshouchuku2saoma.getShuliang3() eq '' || session.xiaoshouchuku2saoma.getShuliang3() eq null}">
                            <div style="margin-top: 20px" th:text="'防火锁数量：'+${@xiaoshouChukuServiceImpl.selectTodo('%防火锁%',
                                 session.xiaoshouchuku2saoma.getChukuDanhao(),session.xiaoshouchuku2saoma.getFahuoDanhao())}"></div>
                            <div style="margin-top: 20px" th:text="'闭门器数量：'+${@xiaoshouChukuServiceImpl.selectTodo('%闭门器%',
                                 session.xiaoshouchuku2saoma.getChukuDanhao(),session.xiaoshouchuku2saoma.getFahuoDanhao())}"></div>
                            <div style="margin-top: 20px"
                                 th:text="'拉爆盖数量：'+${@xiaoshouChukuServiceImpl.selectTodo('%拉爆盖%',
                                 session.xiaoshouchuku2saoma.getChukuDanhao(),session.xiaoshouchuku2saoma.getFahuoDanhao())}"></div>
                        </div>
                </div>
                <div id="zhixing" oncancel="" th:value="${session.xiaoshouchuku2saoma.getZhixing()}" hidden="hidden"></div>
            </div>
        </div>
    </div>
    <script src="./message.js"></script>
    <script th:inline="javascript">
        function check2input4piliang() {
            var text = document.getElementById("msg2saoma").value
            if (text.search("\n") !== -1){
                onAdd()
            }
        }
        function fff(value) {
            console.log(value)
        }

        document.onmousemove = mouseMove;
        var oldx = 0,oldy = 0;
        function mouseMove(event) {
            if(document.getElementById("id2toggle").className ==="fa fa-toggle-on text-info fa-3x"){
                var e = event || window.event;
                var scrollx = document.documentElement.scrollLeft || document.body.scrollTop;
                var scrolly= document.documentElement.scrollTop || document.body.scrollTop;
                var x = e.pageX || e.clientX + scrollx;
                var y = e.pageY || e.clientY + scrolly;
                var input2saoma = document.getElementById("msg2saoma");
                const _select_ = document.activeElement
                if ((x !== oldx || y !== oldy)&&_select_ !== input2saoma){
                    document.getElementById("msg2saoma").focus()
                    //console.log(_select_)
                    oldx = x;oldy=y;
                }
            }
        }
        function check2ZhiXing(value) {
            var _check = value
            $.ajax({
                type:"POST",
                datatype: "string",
                url: "/xiaoshouchuku/SaoMaTest/selectCheck/"+_check,
                data: {},
                async:false,//是否是异步请求
                success: function (result) {
                    _check = result.msg
                    if (_check === "已执行"){
                        alert("该出库单已扫码录入所有出库商品")
                    }
                }
            });
        }
        window.addEventListener('DOMContentLoaded', (event) => {
            change2saoma()
        });
        function change2saoma() {
            var setting = sessionStorage.getItem("toset").toString()
            if (setting === "true"){
                document.getElementById("id2toggle").className= "fa fa-toggle-on text-info fa-3x"
                document.getElementById("msg2saoma").focus()
                sessionStorage.setItem("toset","false")
            }
        }

        function inStart() {

            var id2toggle = document.getElementById("id2toggle").className
            if (id2toggle === "fa fa-toggle-on text-info fa-3x"){
                document.getElementById("id2toggle").className= "fa fa-toggle-off text-info fa-3x"
                document.getElementById("msg2saoma").blur()
            }else {
                document.getElementById("id2toggle").className= "fa fa-toggle-on text-info fa-3x"
                document.getElementById("msg2saoma").focus()
            }
        }

        function onAdd() {
            var msgStr = document.getElementById("msg2saoma").value
            $.ajax({
                type:"POST",
                datatype: "string",
                url: "/xiaoshouchuku/SaoMaTest/inserts",
                data: {"msg": msgStr},
                async:false,//是否是异步请求
                success: function (result) {
                    if (result.code===0) {
                        $.modal.msgSuccess('成功')
                        var a = document.getElementById("id2saoma").getAttribute("value")
                        a = a.replace("\"","")
                        check2ZhiXing(a)
                        SomeOneSaoMa(a)
                    }else {
                        $.modal.msgError(result.msg)
                    }
                    document.getElementById("msg2saoma").value = ""
                    document.getElementById("msg2saoma").focus()
                },
                error : function() {
                    alert("录入失败");
                }
            });
        }
        function SomeOneSaoMa(id) {
            $.ajax({
                type:"POST",
                datatype: "string",
                url: "/xiaoshouchuku/SaoMaTest/selectOne/"+id,
                data: {},
                async:false,//是否是异步请求
                success: function (result) {
                    if (result.code===0) {
                        sessionStorage.setItem("toset","true")
                        $.modal.openTab('开始扫码','/xiaoshouchuku/SaoMaTest/selectOne',true)
                    }else {
                        alert("单据详细未找到")
                    }
                },
                error : function() {
                    alert("后台响应出现问题");
                }
            });
        }
    </script>
</div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
</body>
</html>